package com.ktgj.flight.controller;

import java.util.List;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.flight.domain.KtserviceAirport;
import com.ktgj.flight.service.IKtserviceAirportService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 机场、高铁、港口Controller
 * 
 * @author ruoyi
 * @date 2021-11-10
 */
@ControllerAdvice
@RestController
@RequestMapping("/ktserviceAirport")
public class KtserviceAirportController extends BaseController
{
    @Autowired
    private IKtserviceAirportService KtserviceAirportService;

    /**
     * 查询机场、高铁、港口列表
     */
    @PreAuthorize(hasPermi = "flight:airport:list")
    @GetMapping("/list")
    public TableDataInfo list(KtserviceAirport ktserviceAirport)
    {
        startPage();
        List<KtserviceAirport> list = KtserviceAirportService.selectKtserviceAirportList(ktserviceAirport);
        return getDataTable(list);
    }

    /**
     * 导出机场、高铁、港口列表
     */
    @PreAuthorize(hasPermi = "flight:airport:export")
    @Log(title = "机场、高铁、港口", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, KtserviceAirport ktserviceAirport) throws IOException
    {
        List<KtserviceAirport> list = KtserviceAirportService.selectKtserviceAirportList(ktserviceAirport);
        ExcelUtil<KtserviceAirport> util = new ExcelUtil<KtserviceAirport>(KtserviceAirport.class);
        util.exportExcel(response, list, "机场、高铁、港口数据");
    }

    /**
     * 获取机场、高铁、港口详细信息
     */
    @PreAuthorize(hasPermi = "flight:airport:query")
    @GetMapping(value = "/{airportCode}")
    public AjaxResult getInfo(@PathVariable("airportCode") String airportCode)
    {
        return AjaxResult.success(KtserviceAirportService.selectKtserviceAirportById(airportCode));
    }

    /**
     * 新增机场、高铁、港口
     */
    @PreAuthorize(hasPermi = "flight:airport:add")
    @Log(title = "机场、高铁、港口", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KtserviceAirport ktserviceAirport)
    {
        return toAjax(KtserviceAirportService.insertKtserviceAirport(ktserviceAirport));
    }

    /**
     * 修改机场、高铁、港口
     */
    @PreAuthorize(hasPermi = "flight:airport:edit")
    @Log(title = "机场、高铁、港口", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KtserviceAirport ktserviceAirport)
    {
        return toAjax(KtserviceAirportService.updateKtserviceAirport(ktserviceAirport));
    }

    /**
     * 删除机场、高铁、港口
     */
    @PreAuthorize(hasPermi = "flight:airport:remove")
    @Log(title = "机场、高铁、港口", businessType = BusinessType.DELETE)
	@DeleteMapping(value = "/{airportCodes}")
    public AjaxResult remove(@PathVariable String[] airportCodes)
    {
        return toAjax(KtserviceAirportService.deleteKtserviceAirportByIds(airportCodes));
    }

    /**
     * 根据当前位置查询最近网点
     * */
    @PostMapping(value = "/selectRecentOutlets")
    public AjaxResult selectRecentOutlets(@RequestBody Map<String, Object> map){
        String lng = String.valueOf(map.get("lng"));
        String lat = String.valueOf(map.get("lat"));
        return AjaxResult.success(KtserviceAirportService.selectKtserviceAirportByLngAndLat(lng, lat));
    }

    /**
     * 查询有网点的机场，高铁，港口列表(显示)
     * */
    @PostMapping("/selectTransportationList")
    public AjaxResult selectTransportationList(@RequestBody Map<String, Object> map){
        Long classIficationType = Long.valueOf(map.get("classIficationType").toString());
        String lng = map.get("lng").toString();
        String lat = map.get("lat").toString();
        int count = 1;
        return AjaxResult.success(KtserviceAirportService.selectKtserviceAirportSelectVo(classIficationType, lng, lat, count));
    }

    /**
     * 查询热门机场，高铁，港口列表(显示)
     * */
    @PostMapping("/selectPopularTransportationList")
    public AjaxResult selectPopularTransportationList(@RequestBody Map<String, Object> map){
        Long classIficationType = Long.valueOf(map.get("classIficationType").toString());
        return AjaxResult.success(KtserviceAirportService.selectKtserviceAirportByPopular(classIficationType));
    }

    /**
     * 查询全部高铁
     * */
    @PostMapping("/selectTrain")
    public AjaxResult selectTrain(@RequestBody Map<String, Object> map){
        String lng = map.get("lng").toString();
        String lat = map.get("lat").toString();
        return AjaxResult.success(KtserviceAirportService.selectKtserviceAirportByCities(lng, lat));
    }

    /**
     * 查询热门城市
     * */
    @PostMapping("/selectPopularCities")
    public AjaxResult selectPopularCities(){
        return AjaxResult.success(KtserviceAirportService.selectKtserviceAirportByPopularCities());
    }

    /**
     * 查询全部机场， 高铁，港口列表
     * */
    @PostMapping("/allTransportationList")
    public AjaxResult allTransportationList(@RequestBody Map<String, Object> map){
        Long classIficationType = Long.valueOf(map.get("classIficationType").toString());
        String lng = map.get("lng").toString();
        String lat = map.get("lat").toString();
        int count = 2;
        return AjaxResult.success(KtserviceAirportService.selectKtserviceAirportSelectVo(classIficationType, lng, lat, count));
    }

    /**
     * 查询当前城市的全部机场, 高铁或港口
     * */
    @PostMapping("/allAirport")
    public AjaxResult allAirport(@RequestBody Map<String, Object> map){
        String lng = map.get("lng").toString();
        String lat = map.get("lat").toString();
        String classIficationType = map.get("classIficationType").toString();
        return AjaxResult.success(KtserviceAirportService.selectCitiesAirporVoByPopularCities(lng, lat, classIficationType));
    }
}
